/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import java.awt.Color;
import java.util.ArrayList;

/**
 *
 * @author Snowangelic
 */
public abstract class Clusterization {
    public String name;
    public DataSet dataSet;
    public ArrayList<Cluster> clusterList;
    
    Clusterization(){

    }

    void Clusterization(ClusterizationOptions clusOptions){
        this.name=clusOptions.getName();
        this.dataSet=clusOptions.getDataSet();
        this.clusterList=clusOptions.getClusterList();
        for(int i=0;i<clusterList.size();i++){
            clusterList.get(i).setClusterization(this);
        }
    }

    public Cluster getCluster(int i) {
        return clusterList.get(i);
    }

    public void addCluster(String name,Color color){
        Cluster cluster=new Cluster(dataSet,name,color);
        cluster.setClusterization(this);
        clusterList.add(cluster);
    }

    public void addCluster(String name,String color){
        Cluster cluster=new Cluster(name,color);
        cluster.setClusterization(this);
        clusterList.add(cluster);
    }

    float[] getClusterCoords(int clusterIndex) {
        return clusterList.get(clusterIndex).getCoords();
    }

    public int getClusterNbr() {
        return clusterList.size();
    }

    public Object getValue(int clusterIndex, Attribute attribute, boolean normalized) {
        return clusterList.get(clusterIndex).getValue(attribute,normalized);
    }

    public Color getColor(Action action) {
        // On recherche a quel Cluster appartient l'action
        int clusterIndex=-1;
        for(int i=0;i<clusterList.size();i++){
            if(clusterList.get(i).contains(action)){
                clusterIndex=i;
                break;
            }
        }
        if(clusterIndex!=-1) return clusterList.get(clusterIndex).getColor();
        else return Color.BLACK;
    }

    public String getClusterName(Action action) {
        // On recherche a quel Cluster appartient l'action
        int clusterIndex=-1;
        for(int i=0;i<clusterList.size();i++){
            if(clusterList.get(i).contains(action)){
                clusterIndex=i;
                break;
            }
        }
        if(clusterIndex!=-1) return clusterList.get(clusterIndex).getName();
        else return "";
    }

    public String getClusterName(int clusterIndex) {
        return clusterList.get(clusterIndex).getName();
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

        /**
     * @return the clusterList
     */
    public ArrayList<Cluster> getClusterList() {
        return clusterList;
    }

    public abstract ArrayList<Weight> getWeightList();
    public abstract boolean getNormalized();
    public abstract Distance getDistance();
    public abstract void compute();

    void setClusterName(int clusterIndex, String name) {
        clusterList.get(clusterIndex).setName(name);
    }



}
